#include "drogon/drogon.h"
#include "JobTimer.h"
#include "OCMain/cpptime.h"

#define SeceondsPerHour 3600

namespace ICE_COVER
{
	void JobTimer::start()
	{
		Util::loadConfig();

		std::thread t([this]() {
			while (true)
			{
				this->doJob();
				std::this_thread::sleep_for(std::chrono::seconds((long)SeceondsPerHour));
			}
			});
		t.detach();
	}

	void JobTimer::stop()
	{

	}

	void JobTimer::doJob()
	{
		Date nowTime = Date::now().roundHour();
		if (nowTime.isSameSecond(lastJobTime))
		{
			return;
		}
		lastJobTime = nowTime;
		OCPP_LOG_INFO <<
			"ICE_COVER_JOB:" <<
			lastJobTime.toFormattedStringLocal(false) << "\n";

		Task task;
		task.start();
	}
}
